/**
 * 
 */
package com.bot.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bot.mapper.MajorMapper;
import com.bot.pojo.Area;
import com.bot.pojo.Major;
import com.bot.pojo.Student;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @author zhaoyan
 *
 * 2020年2月4日
 */
@Service
public class MajorServiceImpl implements MajorService{
	
	
	@Autowired
	private MajorMapper majorMapper; 

	@Override
	public PageInfo<Student> findStu(Integer pageNum, Student student) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, 3);
		return new PageInfo<Student>(majorMapper.findStu(student));
	}

	@Override
	public List<Major> findMajor() {
		// TODO Auto-generated method stub
		return majorMapper.findMaj();
	}

	@Override
	public Integer addStu(Student student) {
		// TODO Auto-generated method stub
		
		Integer num = majorMapper.addStu(student);
		
		if(num > 0 && student.getId() > 0) {
			
			majorMapper.addMajS(student);
		}
		
		
		return num;
	}

	@Override
	public Student findStuById(Integer id) {
		// TODO Auto-generated method stub
		return majorMapper.findById(id);
	}

	@Override
	public List<Integer> findMaj(Integer id) {
		// TODO Auto-generated method stub
		return majorMapper.findMajById(id);
	}

	@Override
	public Integer updateStu(Student student) {
		// TODO Auto-generated method stub
		
		//	第一步，改主表
		Integer num = majorMapper.update(student);
		
		if(num > 0) {
			//	删除之前旧的字段
			majorMapper.deleteMajStu(student.getId());
			//	添加新的字段
			majorMapper.addMajS(student);	
		}
		
		
		
		return majorMapper.update(student);
	}

	@Override
	public Integer delStu(List<Integer> ids) {
		// TODO Auto-generated method stub
		
		Integer num = majorMapper.delStu(ids);
		
		if(num > 0) {
			
			
			for (Integer integer : ids) {
				
				majorMapper.deleteMajStu(integer);
			}
			
		}
		return num;
	}

	@Override
	public List<Area> findAreaById(Integer pid) {
		// TODO Auto-generated method stub
		return majorMapper.findAreaList(pid);
	}

}
